package com.hosever.utils;

import java.util.List;

import com.hosever.core.model.OrderBy;

public class OrderByUtils {
	/**
	 * 逆序
	 */
	public static final String ORDER_TYPE_DESC = "desc";
	/**
	 * 顺序
	 */
	public static final String ORDER_TYPE_ASC = "asc";

	/**
	 * 获取排序sql字符串
	 * @param orders
	 * @return
	 */
	public static String getOrderSQL(List<OrderBy> orders){
		if(orders==null || orders.isEmpty()){
			return "";
		}
		String result = " order by ";
		for (OrderBy orderBy : orders) {
			result+=(orderBy.getParameter()+" "+orderBy.getOrderType()+", ");
		}
		result = result.substring(0, result.length()-2);
		return result;
	}
	/**
	 * 获取排序sql字符串
	 * @param order
	 * @return
	 */
	public static String getOrderSQL(OrderBy order){
		if(order == null){
			return "";
		}
		String result = String.format(" order by %s %s", order.getParameter(),order.getOrderType());
		return result;
	}
}
